package com.woniu.guoguo.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.guoguo.model.Menu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.guoguo.model.MenuImg;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Richie
 * @since 2020-11-02
 */
public interface MenuMapper extends BaseMapper<Menu> {

    @Update("update menu set sale_num=sale_num+1 where menu_id=#{id}")
    void addASaleByMenuId(int menuId);

    @Select("select * from menu where restaurant_id=#{id}")
    List<Menu> findMenusByRestId(Integer restaurantId);
    @Select("select * from menu where type like '%${type}%' ")
    IPage<Menu> getmenubutype(Page<Menu> page,String type);
    @Select("SELECT (SELECT menu_img.img_path FROM menu_img WHERE menu_img.menu_id = t1.menu_id LIMIT 0, 1) FROM menu AS t1 WHERE t1.type like '%${type}%' ")
    IPage<String> getmenuimgbytype(Page<String> page, String type);
    @Select("select * from menu where type like '%${type}%' order by sale_num desc")
    IPage<Menu> xlgetmenu(Page<String> page, String type);
    @Select("SELECT (SELECT menu_img.img_path FROM menu_img WHERE menu_img.menu_id = t1.menu_id LIMIT 0, 1) FROM menu AS t1 WHERE t1.type like '%${type}%' order by sale_num desc")
    IPage<String> xlgetmenuimg(Page<String> page, String type);
    @Select("select * from menu where type like '%${type}%' order by price asc")
    IPage<Menu> jggetmenu(Page<String> page, String type);
    @Select("SELECT (SELECT menu_img.img_path FROM menu_img WHERE menu_img.menu_id = t1.menu_id LIMIT 0, 1) FROM menu AS t1 WHERE t1.type like '%${type}%' order by price asc")
    IPage<String> jggetmenuimg(Page<String> page, String type);

    //根据名字
    @Select("select * from menu where menu_name like '%${name}%' ")
    IPage<Menu> getmenubuname(Page<Menu> page,String name);
    @Select("SELECT (SELECT menu_img.img_path FROM menu_img WHERE menu_img.menu_id = t1.menu_id LIMIT 0, 1) FROM menu AS t1 WHERE t1.menu_name like '%${name}%' ")
    IPage<String> getmenuimgbyname(Page<String> page, String name);
    @Select("select * from menu where menu_name like '%${name}%' order by sale_num desc")
    IPage<Menu> xlgetmenu2(Page<String> page, String name);
    @Select("SELECT (SELECT menu_img.img_path FROM menu_img WHERE menu_img.menu_id = t1.menu_id LIMIT 0, 1) FROM menu AS t1 WHERE t1.menu_name like '%${name}%' order by sale_num desc")
    IPage<String> xlgetmenuimg2(Page<String> page, String name);
    @Select("select * from menu where menu_name like '%${name}%' order by price asc")
    IPage<Menu> jggetmenu2(Page<String> page, String name);
    @Select("SELECT (SELECT menu_img.img_path FROM menu_img WHERE menu_img.menu_id = t1.menu_id LIMIT 0, 1) FROM menu AS t1 WHERE t1.menu_name like '%${name}%' order by price asc")
    IPage<String> jggetmenuimg2(Page<String> page, String name);
}
